package com.leyou.sms.config;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 通过@Bean注册阿里客户端到Spring
 */
@Configuration
public class SmsConfiguration {

    @Bean
    public IAcsClient acsClient(SmsProperties properties){
        DefaultProfile profile = DefaultProfile.getProfile(
                properties.getRegionID(),properties.getAccessKeyID(),properties.getAccessKeySecret());

        IAcsClient client = new DefaultAcsClient(profile);

        return client;
    }

    //消息转换器  保证发送的消息是json格式
    @Bean
    public MessageConverter messageConverter(){
        return new Jackson2JsonMessageConverter();
    }
}
